package athabasca.ca.model;

import java.util.ArrayList;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class User
{
	private long userId;
	private String userPassword;
	private String firstName;
	private String lastName;
	private String birthday;
//	private String[] telephones;
	private ArrayList<String> telephones;
//	private String[] emails;
	private ArrayList<String> emails;
	private String otherPreferences;
	
	public User()
	{
		telephones = new ArrayList<String>( );
		emails = new ArrayList<String>( );
	}
	
	public User(long userId)
	{
		this.userId = userId;
		
		telephones = new ArrayList<String>( );
		emails = new ArrayList<String>( );
	}
	
	public User(long userId, String password)
	{
		this.userId = userId;
		this.userPassword = password;
		
		telephones = new ArrayList<String>( );
		emails = new ArrayList<String>( );
	}
	
//	public User(long userId, String password,
//			String firstName, String lastName, String birthday,
//			String[] telephones, String[] emails, String otherPreferences)
//	{
//		this.userId = userId;
//		this.userPassword = password;
//		this.firstName = firstName;
//		this.lastName = lastName;
//		this.birthday = birthday;
//		
//		this.emails = new String[emails.length];
//		for(int i = 0; i < emails.length; ++i)
//		{
//			this.emails[i] = emails[i];
//		}
//		
//		this.telephones = new String[telephones.length];
//		for(int i = 0; i < telephones.length; ++i)
//		{
//			this.telephones[i] = telephones[i];
//		}
//		
//		this.otherPreferences = otherPreferences;
//	}
	
	public User(long userId, String password,
			String firstName, String lastName, String birthday,
			String[] telephones, String[] emails, String otherPreferences)
	{
		this.userId = userId;
		this.userPassword = password;
		this.firstName = firstName;
		this.lastName = lastName;
		this.birthday = birthday;
		
		this.emails = new ArrayList<String>( );
		for( String email : emails)
		{
			this.emails.add( email );
		}
		
		this.telephones = new ArrayList<String>( );
		for( String telephone : telephones)
		{
			this.telephones.add( telephone );
		}
		
		this.otherPreferences = otherPreferences;
	}
	
	public User (String password,
			String firstName, String lastName, String birthday,
			String[] telephones, String[] emails, String otherPreferences)
	{
		this.userPassword = password;
		this.firstName = firstName;
		this.lastName = lastName;
		this.birthday = birthday;
		
		this.emails = new ArrayList<String>( );
		for( String email : emails)
		{
			this.emails.add( email );
		}
		
		this.telephones = new ArrayList<String>( );
		for( String telephone : telephones)
		{
			this.telephones.add( telephone );
		}
		
		this.otherPreferences = otherPreferences;
	}
	
	//setters and getters
	public long getUserId()
	{
		
		return userId;
	}
	
	public void setUserId(long userId)
	{
		this.userId = userId;
	}
	
	public String getPassword()
	{
		return userPassword;
	}
	
	public void setPassword(String password)
	{
		this.userPassword = password;
	}
	
	public String getFirstName()
	{
		return firstName;
	}
	
	public void setFirstName(String firstName)
	{
		this.firstName = firstName;
	}
	
	public String getLastName()
	{
		return lastName;
	}
	
	public void setLastName(String lastName)
	{
		this.lastName = lastName;
	}
	
	public String getBirthday()
	{
		return birthday;
	}
	
	public void setBirthday(String birthday)
	{
		this.birthday = birthday;
	}
	
	public String[] getTelephones()
	{
		return (String[ ] ) telephones.toArray ( new String[ telephones.size( ) ] );
	}
	
	public void addTelephone ( String telephone )
	{
		telephones.add( telephone );
	}
	
	public void addTelephones(String[] telephones)
	{
		for( String telephone : telephones)
		{
			this.telephones.add(  telephone );
		}
	}
	
	public void removeTelephone( String telephone )
	{
		this.telephones.remove ( telephone );
	}
	
	public String[] getEmails()
	{
		return ( String[ ] ) emails.toArray( new String[ emails.size( ) ] ); 
	}
	
	public void addEmail ( String email )
	{
		emails.add( email );
	}
	
	public void addEmails(String[] emails)
	{
		for( String email: emails)
		{
			this.emails.add( email );
		}
	}
	
	public void removeEmail( String email )
	{
		if ( this.emails.contains ( email ) )
			this.emails.remove ( email );
	}
	
	public String getOtherPreferences()
	{
		return otherPreferences;
	}
	
	public void setOtherPreferences(String otherPreferences)
	{
		this.otherPreferences = otherPreferences;
	}
	
	@Override
	public String toString( )
	{
		String result = this.userId + " " + this.userPassword + "\n" + this.firstName + " " + this.lastName + "\n";
		for(String phone : telephones)
		{
			result += phone + " ";
		}
		for(String email : emails)
		{
			result += email + " ";
		}
		
		result += this.otherPreferences;
		
		return result;
	}
	
}

